/**
 *    Copyright (C) 2008  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_TOOLS_TYPES_ALGO_SELECT_HPP
#define	_CUBEFS_CORE_TOOLS_TYPES_ALGO_SELECT_HPP

#include <cubefs/core/tools/types/typelist.hpp>
#include <cubefs/api/types.hpp>



namespace cubefs    {
namespace tools     {

template <Int Value, typename List, Int idx = 0> struct Select;

template <Int Value, typename Head, typename Tail>
struct Select<Value, TypeList<Head, Tail>, Value> {
    typedef Head                                                                Result;
};

template <Int Value, typename Head, typename Tail, Int Idx>
struct Select<Value, TypeList<Head, Tail>, Idx> {
    typedef typename Select<Value, Tail, Idx + 1>::Result                       Result;
};

template <Int Value, Int Idx>
struct Select<Value, NullType, Idx> {
    typedef ListIndexOutOfRange<Value>                                          Result;
};

template <bool Value, typename ResultIfTrue, typename Else>
struct IfThenElse {
    typedef typename Select<
                Value ? 0 : 1,
                TypeList<ResultIfTrue, TypeList<Else> >
    >::Result                                                                   Result;
};


template <typename Type1, typename Type2>
struct IfTypesEqual {
    static const bool Value = false;
};

template <typename Type>
struct IfTypesEqual<Type, Type> {
    static const bool Value = true;
};


}
}

#endif  //_CUBEFS_CORE_TOOLS_TYPES_ALGO_SELECT_HPP